import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'
import { quillEditor } from 'vue-quill-editor';
/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/

//----------------------------------------------------------1------------------------------------------------------------------
const constantRouterMap1 = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: 'product',
    name: '/kkg',
    meta: { title: '商品管理' },
    children: [
      {
        path: 'product',
        name: 'product',
        component: () => import('@/views/kkg/goods/index'),
        meta: { title: '商品列表'},
        hidden: true
      },
      {
        path: 'productDetails',
        name: 'productDetails',
        component: () => import('@/views/kkg/goods/details'),
        meta: { title: '商品详情' },
        hidden: true
      },
      {
        path: 'addProduct',
        name: 'addProduct',
        component: () => import('@/views/kkg/goods/add'),
        meta: { title: '发布商品' }
      },
      {
        path: 'updateProduct',
        name: 'updateProduct',
        component: () => import('@/views/kkg/goods/update'),
        meta: { title: '发布商品' },
        hidden: true
      }
    ]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/orderForm',
    name: 'oms',
    meta: { title: '订单管理' },
    children: [
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/kkg/orderForm/index'),
        meta: { title: '订单列表'}
      },
      {
        path: 'orderdetail',
        name: 'orderdetail',
        component: () => import('@/views/kkg/orderForm/details'),
        meta: { title: '订单详情' },
        hidden: true
      },
    ]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/agent',
    name: 'agent',
    meta: { title: '代理管理'},
    children: [
      {
        path: 'agentindex',
        name: 'agentindex',
        component: () => import('@/views/kkg/agent/index'),
        meta: { title: '代理列表' }
      },
      {
        path: 'detail',
        name: 'detail',
        component: () => import('@/views/kkg/agent/details'),
        meta: { title: '代理详情' },
        hidden: true
      },
    ]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/member',
    children: [
      {
        path: 'member',
        name: 'member',
        component: () => import('@/views/kkg/member/index'),
        meta: { title: '会员管理' }
      },
      {
        path: '/member/detail',
        name: 'detail',
        component: () => import('@/views/kkg/member/details'),
        meta: { title: '会员管理详情' },
        hidden: true
      }
    ]
  },
  {

    path: '/kkg',
    component: Layout,
    redirect: '/kkg/integralRule',
    children: [{
      path: 'integralRule',
      name: 'integralRule',
      component: () => import('@/views/kkg/integralRule/index'),
      meta: { title: '积分管理'}
    }]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/sale',
    children: [{
      path: 'sale',
      name: 'sale',
      component: () => import('@/views/kkg/sale/index'),
      meta: { title: '销售统计' }
    }]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/business',
    children: [{
      path: 'business',
      name: 'business',
      component: () => import('@/views/kkg/business/index'),
      meta: { title: '经营统计' }
    }]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/permission',
    children: [{
      path: 'permission',
      name: 'permission',
      component: () => import('@/views/kkg/permission/index'),
      meta: { title: '权限管理' }
    }]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/banner',
    children: [
      {
        path: 'banner',
        name: 'banner',
        component: () => import('@/views/kkg/banner/index'),
        meta: { title: 'banner管理'}
      },
      {
        path: 'banneradd',
        name: 'banneradd',
        component: () => import('@/views/kkg/banner/add'),
        meta: { title: 'banner管理新增' },
        hidden: true
      },
      {

        path: 'updateBanner',
        name: 'updateBanner',
        component: () => import('@/views/kkg/banner/update'),
        meta: { title: 'banner管理编辑' },
        hidden: true
      }
    ]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/paramSetting',
    children: [{
      path: 'paramSetting',
      name: 'paramSetting',
      component: () => import('@/views/kkg/paramSetting/index'),
      meta: { title: '参数设置'}
    }]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/feedback',
    children: [
      {
        path: 'feedback',
        name: 'feedback',
        component: () => import('@/views/kkg/feedback/index'),
        meta: { title: '反馈管理' }
      },
      {
        path: 'template',
        name: 'template',
        component: () => import('@/views/kkg/feedback/template'),
        meta: { title: '反馈模板' },
        hidden: true
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

//----------------------------------------------------------2------------------------------------------------------------------
const constantRouterMap2 = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/kkg',
    component: Layout,
    redirect: 'product',
    name: '/kkg',
    meta: { title: '商品管理' },
    children: [
      {
        path: 'product',
        name: 'product',
        component: () => import('@/views/kkg/goods/index'),
        meta: { title: '商品列表'},
        hidden: true
      },
      {
        path: 'productDetails',
        name: 'productDetails',
        component: () => import('@/views/kkg/goods/details'),
        meta: { title: '商品详情' },
        hidden: true
      },
      {
        path: 'addProduct',
        name: 'addProduct',
        component: () => import('@/views/kkg/goods/add'),
        meta: { title: '发布商品' }
      },
      {
        path: 'updateProduct',
        name: 'updateProduct',
        component: () => import('@/views/kkg/goods/update'),
        meta: { title: '发布商品' },
        hidden: true
      }
    ]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/orderForm',
    name: 'oms',
    meta: { title: '订单管理' },
    children: [
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/kkg/orderForm/index'),
        meta: { title: '订单列表'}
      },
      {
        path: 'orderdetail',
        name: 'orderdetail',
        component: () => import('@/views/kkg/orderForm/details'),
        meta: { title: '订单详情' },
        hidden: true
      },
    ]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/agent',
    name: 'agent',
    meta: { title: '代理管理'},
    children: [
      {
        path: 'agentindex',
        name: 'agentindex',
        component: () => import('@/views/kkg/agent/index'),
        meta: { title: '代理列表' }
      },
      {
        path: 'detail',
        name: 'detail',
        component: () => import('@/views/kkg/agent/details'),
        meta: { title: '代理详情' },
        hidden: true
      },
    ]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/member',
    children: [
      {
        path: 'member',
        name: 'member',
        component: () => import('@/views/kkg/member/index'),
        meta: { title: '会员管理' }
      },
      {
        path: '/member/detail',
        name: 'detail',
        component: () => import('@/views/kkg/member/details'),
        meta: { title: '会员管理详情' },
        hidden: true
      }
    ]
  },
  {

    path: '/kkg',
    component: Layout,
    redirect: '/kkg/integralRule',
    children: [{
      path: 'integralRule',
      name: 'integralRule',
      component: () => import('@/views/kkg/integralRule/index'),
      meta: { title: '积分管理'}
    }]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/sale',
    children: [{
      path: 'sale',
      name: 'sale',
      component: () => import('@/views/kkg/sale/index'),
      meta: { title: '销售统计' }
    }]
  },

  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/permission',
    children: [{
      path: 'permission',
      name: 'permission',
      component: () => import('@/views/kkg/permission/index'),
      meta: { title: '权限管理' }
    }]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/banner',
    children: [
      {
        path: 'banner',
        name: 'banner',
        component: () => import('@/views/kkg/banner/index'),
        meta: { title: 'banner管理'}
      },
      {
        path: 'banneradd',
        name: 'banneradd',
        component: () => import('@/views/kkg/banner/add'),
        meta: { title: 'banner管理新增' },
        hidden: true
      },
      {

        path: 'updateBanner',
        name: 'updateBanner',
        component: () => import('@/views/kkg/banner/update'),
        meta: { title: 'banner管理编辑' },
        hidden: true
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

//----------------------------------------------------------3------------------------------------------------------------------
const constantRouterMap3 = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/orderForm',
    name: 'oms',
    meta: { title: '订单管理' },
    children: [
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/kkg/orderForm/index'),
        meta: { title: '订单列表'}
      },
      {
        path: 'orderdetail',
        name: 'orderdetail',
        component: () => import('@/views/kkg/orderForm/details'),
        meta: { title: '订单详情' },
        hidden: true
      },
    ]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/agent',
    name: 'agent',
    meta: { title: '代理管理'},
    children: [
      {
        path: 'agentindex',
        name: 'agentindex',
        component: () => import('@/views/kkg/agent/index'),
        meta: { title: '代理列表' }
      },
      {
        path: 'detail',
        name: 'detail',
        component: () => import('@/views/kkg/agent/details'),
        meta: { title: '代理详情' },
        hidden: true
      },
    ]
  },
  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/member',
    children: [
      {
        path: 'member',
        name: 'member',
        component: () => import('@/views/kkg/member/index'),
        meta: { title: '会员管理' }
      },
      {
        path: '/member/detail',
        name: 'detail',
        component: () => import('@/views/kkg/member/details'),
        meta: { title: '会员管理详情' },
        hidden: true
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

//----------------------------------------------------------4------------------------------------------------------------------
const constantRouterMap4 = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },


  {
    path: '/kkg',
    component: Layout,
    redirect: '/kkg/feedback',
    children: [
      {
        path: 'feedback',
        name: 'feedback',
        component: () => import('@/views/kkg/feedback/index'),
        meta: { title: '商家管理' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

////不同角色展示不同菜单
debugger
var temp = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true }]

var userInfo=JSON.parse(localStorage.getItem("userInfo"))
if(userInfo){
  var roleId=userInfo.roleId
  // console.log(roleId,9999999999999)
  if(roleId==1){
    temp = constantRouterMap1
  }else if(roleId==2){
    temp = constantRouterMap2
  }else if(roleId==3){
    temp = constantRouterMap3
  }else if(roleId==4){
    temp = constantRouterMap4
  }

}

export const constantRouterMap = temp


export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

